package com.guigu.guliware.controller;


import com.guigu.gulicommon.entity.dto.WareSkuLockDto;
import com.guigu.gulicommon.entity.pojo.res.Res;
import com.guigu.gulicommon.entity.vo.HasStockSkuVo;
import com.guigu.gulicommon.entity.vo.LockStockVo;
import com.guigu.guliware.service.IWmsWareSkuService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

import static com.guigu.gulicommon.constant.CheckParametersConstant.SKU_ID_CANNOT_BE_NULL;

/**
 * 商品库存
 * </p>
 *
 * @author 陈俊杰
 * @since 2024-08-24
 */
@RestController
@RequestMapping("/wms-ware-sku")
@Log4j2
@Validated
public class WmsWareSkuController {
    @Autowired
    private IWmsWareSkuService wmsWareSkuService;

    /**
     * 根据skuId查询商品库存
     *
     * @param skuIds skuIds
     * @return 单款商品库存信息
     */
    @PostMapping("/stockBySkuIds")
    public Res<HasStockSkuVo> getStockBySkuId(
            @RequestBody
            @NotNull(message = SKU_ID_CANNOT_BE_NULL)
            List<Long> skuIds
    ) {
        log.info("根据skuId查询商品库存入参为:[{}]", skuIds);
        return wmsWareSkuService.getStockBySkuIds(skuIds);
    }

    /**
     * 锁定订单对应的商品库存
     *
     * @param wareSkuLockDto 锁定库存信息
     * @return 锁定结果
     */
    @PostMapping("/lockStock")
    public Res<LockStockVo> orderLockStock(@Validated @RequestBody WareSkuLockDto wareSkuLockDto) {
        log.info("锁定订单对应的商品库存入参为:[{}]", wareSkuLockDto);
        return wmsWareSkuService.orderLockStock(wareSkuLockDto);
    }


}
